package name.sraynal.msgdispatcher.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import name.sraynal.msgdispatcher.controller.Controller;
import name.sraynal.msgdispatcher.event.Event;

public class EndView extends View {

	public EndView(Controller[] controllers) {
		super(controllers);
		
		List menu = new List("end menu", List.IMPLICIT);
		menu.append("done", null);
		menu.append("go on", null);
		menu.append("to other file", null);
		this.displayable = menu;
		
		this.displayable.addCommand(new Command("stop", Command.STOP, 0));
		this.displayable.setCommandListener(new ListListener(menu));
	}
	
	class ListListener implements CommandListener {
		
		private List list;

		public ListListener(List list) {
			super();
			this.list = list;
		}

		public void commandAction(Command arg0, Displayable arg1) {
			if (list.getSelectedIndex() == 0) {
				sendEvent(new Event(Event.END_APP));
			} else if (list.getSelectedIndex() == 1) {
				sendEvent(new Event(Event.BACK_TO_BEGINNING));
			} else if (list.getSelectedIndex() == 2) {
				sendEvent(new Event(Event.SECOND_FILE_DEST));
			}
		}
	}
}
